package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.InformationRecruitment;
import com.huilai.platform.country_platform.model.PartyActivities;
import com.huilai.platform.country_platform.model.UserRecruitment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/2/26
 * 注释：
 */
public interface UserRecruitmentReposity extends JpaRepository<UserRecruitment, Integer>, JpaSpecificationExecutor<UserRecruitment> {
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into user_recruitment(user_id, recruitment_id) values (:userId, :recruitmentId)", nativeQuery = true)
    Integer addUserRecruitment(Integer userId, Integer recruitmentId);

    UserRecruitment findUserRecruitmentByUserIdAndRecruitmentId(Integer userId, Integer recruitmentId);

    UserRecruitment findUserRecruitmentByRecruitmentId(Integer recruitmentId);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("delete from UserRecruitment ur where ur.id = :id")
    Integer deleteUserRecruitment(Integer id);

//    @Modifying(clearAutomatically = true)
//    @Transactional
//    @Query(value = "update user_recruitment pa set "+
//            "pa.describe = :#{#userRecruitment.describe} where pa.id = :#{#userRecruitment.id}",nativeQuery = true)
//    Integer updateUserRecruitment(UserRecruitment userRecruitment);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update user_recruitment pa set pa.describe = :describe, " +
            "pa.unread = 1 where pa.id = :id",nativeQuery = true)
    Integer updateUserRecruitment(Integer id, String describe);
}
